package org.example.springprinciple.scope;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.ApplicationScope;
import org.springframework.web.context.annotation.RequestScope;
import org.springframework.web.context.annotation.SessionScope;

@Component
public class BeanConfig {
    @Bean
    public Dog dog() {
        return new Dog();
    }
    //这些代码是用来实验bean的作用域的
    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
    @Bean
    public Dog single() {
        return new Dog();
    }

    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    @Bean
    public Dog prototype() {
        return new Dog();
    }

    @RequestScope
    @Bean
    public Dog request() {
        return new Dog();
    }
    @SessionScope
    @Bean
    public Dog session() {
        return new Dog();
    }
    @ApplicationScope
    @Bean
    public Dog application() {
        return new Dog();
    }
}
